package cn.jvtc.jx.login_sp0604;

import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class SaveDataUtil {
    public void saveData(Context context, String pwd) throws IOException {
        String result=pwd;
        // /data/data/cn.jvtc.jx.sp0604
        String path = context.getFilesDir().getPath();
        //创建user.txt文件
        File file=new File(path,"user.txt");
        //将文件写入 第一种方式
        FileOutputStream outputStream=new FileOutputStream(file);
        //第二种方式 字节流
        //FileOutputStream fileOutputStream = context.openFileOutput("user.txt", Context.MODE_PRIVATE);
        outputStream.write(result.getBytes());
        outputStream.close();
    }
    /*
    *读取数据
     */
    public String[] getUserInfo(Context context) throws IOException {
        FileInputStream inputStream=context.openFileInput("user.txt");
        InputStreamReader inputStreamReader=new InputStreamReader(inputStream);
        BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
        String data = bufferedReader.readLine();
        Log.d( "getUserInfo: ",data);
        String[] split = data.split(" ");// admin  123456
        return split;
    }
}
